<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<div>
    <button onclick="doAjaxGet()">do Ajax Get</button>
    <button onclick="doAjaxPost()">do Ajax Post</button>
    <button onclick="doAjaxDelete()">do Ajax Delete</button>
    <button onclick="doAjaxUpdate()">do Ajax Update</button>
</div>

<div id="result"></div>

<div>
    <script>
        function doAjaxGet() {
            let xhr = new XMLHttpRequest();
            xhr.onreadystatechange = function () {
                if (xhr.readyState == 4 && xhr.status == 200) {
                    document.getElementById("result").innerHTML = xhr.responseText;
                }
            }
            xhr.open("get", "http://localhost:8080/doAjaxGet", true);
            xhr.send(null);
        }

        function doAjaxPost() {
            let xhr = new XMLHttpRequest();
            xhr.onreadystatechange=function () {
                if (xhr.readyState==4&&xhr.status==200){
                    document.getElementById("result").innerHTML=xhr.responseText;
                }
            }
            xhr.open("post","http://localhost:8080/doAjaxPost",true);
            xhr.setRequestHeader("Content-Type","application/x-www-form-urlencoded")
            xhr.send("id=9528&name=唐&remark=书山有路勤为径，学海无涯苦作舟");
        }

        function doAjaxDelete() {
            let xhr = new XMLHttpRequest();
            xhr.onreadystatechange=function () {
                if (xhr.readyState==4&&xhr.status==200){
                    document.getElementById("result").innerHTML=xhr.responseText;
                }
            }
            xhr.open("delete","http://localhost:8080/doAjaxDelete/9528",true);
            // xhr.setRequestHeader("Content-Type","application/x-www-form-urlencoded")
            xhr.send(null);
        }


        function doAjaxUpdate() {
            let xhr = new XMLHttpRequest();
            xhr.onreadystatechange=function () {
                if (xhr.readyState==4&&xhr.status==200){
                    document.getElementById("result").innerHTML=xhr.responseText;
                }
            }
            xhr.open("put","http://localhost:8080/doAjaxUpdate",true);
            xhr.setRequestHeader("Content-Type","application/x-www-form-urlencoded")
            xhr.send("id=9528&name=秦&remark=南登碣石阪，遥望黄金台。");
        }
    </script>
</div>
</body>
</html>